import PanelBase from "../common/PanelBase";
import Utils from "../core/Utils";
import SDKHelper from "../core/sdk/SDKHelper";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SidebarManager extends PanelBase {

    @property(cc.Node)
    btnClose: cc.Node = null;
    @property(cc.Node)
    btnSidebar: cc.Node = null;

    private successCallback: Function;
    private failCallback: Function;

    onLoad() {
        Utils.Instance.addCallbackToButton(this.btnClose, this.node, "SidebarManager", "onCloseTouch");
        Utils.Instance.addCallbackToButton(this.btnSidebar, this.node, "SidebarManager", "onEnterSidebarTouch");
    }

    start() {

    }

    public showSidebarLayer(options: { success: Function, fail: Function }) {
        this.successCallback = options.success;
        this.failCallback = options.fail;
        this.node.active = true;
    }

    private onCloseTouch() {
        this.onClose();
    }

    private onEnterSidebarTouch() {
        SDKHelper.Instance.ttShowSidebar({
            success: () => {
                this.successCallback && this.successCallback();
            },
            fail: () => {
                this.failCallback && this.failCallback();
            }
        })
    }

    // update (dt) {}
}
